package com.fb;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.fb.FileBrowserPage;
import com.dev.IconView;
import com.dev.IconViewClose;
import com.dev.MainActivity;
import com.dev.QueryNewImage;

class WhichTypeWillBeCreate extends LinearLayout implements OnClickListener{
	private WindowManager.LayoutParams wlp=new WindowManager.LayoutParams();
	TextView title;
	LinearLayout titlebar;
	LinearLayout bottombar;
	IconView close;
	FileBrowserPage.Item itFile;
	FileBrowserPage.Item itFolder;
	FileBrowserPage.Item itImage;
	FileBrowserPage.Item itSVG;
	FileBrowserPage.Item itHtml;
	FileBrowserPage.Item itVector;
	FileBrowserPage.Item itSymlink;
	FileBrowserPage fbp;

	MainActivity ma;
	public WhichTypeWillBeCreate(MainActivity ma){
		super(ma);
		this.ma=ma;
		setOrientation(VERTICAL);
		setWillNotDraw(false);
		title=new TextView(ma);
		title.setText("新建");
		title.setTextColor(0xff000000);
		title.setTextSize(TypedValue.COMPLEX_UNIT_DIP,15);
		title.setGravity(Gravity.CENTER_VERTICAL);
		title.setPadding(9,0,0,0);
		close=new IconViewClose(ma);
		close.setOnClickListener(this);
		titlebar=new LinearLayout(ma){
			public void onDraw(Canvas cvs){
				super.onDraw(cvs);
				Paint p=new Paint();
				p.setColor(FileBrowserPage.borderColor);
				cvs.drawRect(0,getHeight()-FileBrowserPage.borderWidth,getWidth(),getHeight(),p);
			}
		};
		titlebar.setWillNotDraw(false);
		titlebar.setOrientation(HORIZONTAL);
		titlebar.addView(title,new LayoutParams(0,-1,1));
		titlebar.addView(close);
		//tblp=new LayoutParams(0,-1,1);
		itFile=new FileBrowserPage.Item(ma);
		itFile.setText("文件");
		itFile.setOnClickListener(this);
		itFolder=new FileBrowserPage.Item(ma);
		itFolder.setText("文件夹");
		itFolder.setOnClickListener(this);
		itSymlink=new FileBrowserPage.Item(ma);
		itSymlink.setText("软链接");
		itSymlink.setOnClickListener(this);
		itImage=new FileBrowserPage.Item(ma);
		itImage.setText("图像");
		itImage.setOnClickListener(this);
		itSVG=new FileBrowserPage.Item(ma);
		itSVG.setText("svg文档");
		itSVG.setOnClickListener(this);
		itHtml=new FileBrowserPage.Item(ma);
		itHtml.setText("html文档");
		itHtml.setOnClickListener(this);
		itVector=new FileBrowserPage.Item(ma);
		itVector.setText("android vector xml文档");
		itVector.setOnClickListener(this);
		addView(titlebar,-1,(int)(30*ma.dp));
		addView(itFolder,-1,-2);
		addView(itFile,-1,-2);
		addView(itSymlink,-1,-2);
		addView(itImage,-1,-2);
		addView(itSVG,-1,-2);
		addView(itHtml,-1,-2);
		addView(itVector);
	}
	public void show(FileBrowserPage fbp){
		this.fbp=fbp;
		wlp.width=fbp.getWidth()*3/4;
		wlp.height=-2;

		ma.wm.addView(this,wlp);
	}
	void dismiss(){
		ma.wm.removeView(this);
	}
	@Override
	public void onClick(View v){
		if(ma.queryNewFile==null)ma.queryNewFile=new QueryCreate(ma);
		if(v==itFile){
			ma.queryNewFile.createType=0;
			ma.queryNewFile.show(fbp);
			dismiss();
		}else if(v==itFolder){
			ma.queryNewFile.createType=1;
			ma.queryNewFile.show(fbp);
			dismiss();
		}else if(v==itSymlink){
			ma.queryNewFile.createType=5;
			ma.queryNewFile.show(fbp);
			dismiss();
		}else if(v==itSVG){
			ma.queryNewFile.createType=2;
			ma.queryNewFile.show(fbp);
			dismiss();
		}else if(v==itHtml){
			ma.queryNewFile.createType=3;
			ma.queryNewFile.show(fbp);
			dismiss();
		}else if(v==itVector){
			ma.queryNewFile.createType=4;
			ma.queryNewFile.show(fbp);
			dismiss();
		}else if(v==itImage){
			if(QueryNewImage.qni==null)QueryNewImage.qni=new QueryNewImage(ma);
			QueryNewImage.qni.show();
			dismiss();
		}else if(v==close){
			dismiss();
		}
	}
	@Override
	protected void onDraw(Canvas canvas){
		Paint p=new Paint();
		p.setColor(FileBrowserPage.borderColor);
		p.setStyle(Paint.Style.FILL);
		canvas.drawColor(0xffffffff);
		canvas.drawRect(0,0,FileBrowserPage.borderWidth,getHeight(),p);
		canvas.drawRect(0,0,getWidth(),FileBrowserPage.borderWidth,p);
		canvas.drawRect(getWidth()-FileBrowserPage.borderWidth,0,getWidth(),getHeight(),p);
		canvas.drawRect(0,getHeight()-FileBrowserPage.borderWidth,getWidth(),getHeight(),p);
		super.onDraw(canvas);
	}

}
